﻿using Stock.Model;
using Stock.Util;

namespace Stock.Service
{
    public class AppConfigService : BaseService
    {
        private readonly string file_name = "app_config.json";

        /// <summary>
        /// 获得配置
        /// </summary>
        /// <returns></returns>
        public AppConfigModel GetConfigModel()
        {
            string path = GetFilePath(file_name);
            string json = FileUtil.ReadAllText(path);
            if (string.IsNullOrEmpty(json))
            {
                return new AppConfigModel();
            }
            var model= StringUtil.Parse<AppConfigModel>(json);
            model.Valid();
            return model;
        }

        public void Update(AppConfigModel model)
        {
            string path = GetFilePath(file_name);
            FileUtil.WriteAllText(path, StringUtil.ToJson(model));
        }
    }
}
